package com.tdam2011.grupo02.messagesender;

import java.util.ArrayList;

import com.tdam2011.grupo02.domain.MensajeWeb;

public class WebServiceSingleton {

	private WebService webService = null;
	private static WebServiceSingleton webServiceSingleton = null;

	private WebServiceSingleton(String username, String password) {
		webService = new WebService(username, password);
	}

	private static void createInstance(String username, String password) {
		if (webServiceSingleton == null)
			webServiceSingleton = new WebServiceSingleton(username, password);
	}

	public static WebServiceSingleton getInstance(String username,
			String password) {
		if (webServiceSingleton == null)
			createInstance(username, password);
		webServiceSingleton.setUser(username, password);
		
		return webServiceSingleton;
	}

	public WebServiceInfo registerUser() {
		return webService.registerUser();
	}

	public WebServiceInfo sendMessage(MensajeWeb msgw) {
		return webService.sendMessage(msgw);
	}
	
	public ArrayList<ReceivedMessageInfo> getMessages(String timestamp) {
		return webService.getMessages(timestamp);
	}

	public void setUser(String username, String password) {
		webService.setUser(username, password);
	}

}
